package com.boot.es.web;

import com.boot.es.es.PhoneES;
import com.boot.es.lang.Result;
import com.boot.es.service.PhoneService;
import com.boot.es.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @date 2020/10/27 9:50
 */
@RestController
@RequestMapping("es")
public class PhoneController {

    @Autowired
    private PhoneES phoneES;

    @RequestMapping("/list/{keywords}")
    public Result list(@PathVariable("keywords") String keyword) throws IOException {
        return ResultUtil.success(phoneES.parseContent(keyword));
    }


    @RequestMapping("/search/{keyword}/{pageNo}/{pageSize}")
    public Result search(@PathVariable("keyword") String keyword,
                         @PathVariable("pageNo") int pageNo,
                         @PathVariable("pageSize") int pageSize) throws IOException {
        return ResultUtil.success(phoneES.searchPage(keyword, pageNo, pageSize));
    }

}
